#version 130
#extension GL_EXT_texture_array : enable

uniform sampler2DArray vegetationTexture;
uniform sampler2D noiseTexture;
uniform vec3 sunPosition;
uniform vec3 playerPosition;

in vec3 fWorldPos;
in vec2 fTexcoord;
in vec3 fNormal;
in vec4 fColor;
in float fAlpha;

void main()
{   
    vec4 color = texture2DArray(vegetationTexture, vec3(fTexcoord.st, 0));
    
    float noise = texture2D(noiseTexture, vec2(fWorldPos.st * 0.1)).r;        
    color.rgb = mix(color.rgb, color.rgb * 0.5, noise);
    
    if (color.a < 0.5 || fAlpha == 0)
    {		
			discard;
	} 
	else 
	{
		gl_FragColor = fColor * vec4(color.rgb, fAlpha);
    }    
}
